package com.fenxiangtech.mall.dao;

import com.fenxiangtech.mall.entity.Order;
import com.fenxiangtech.mall.entity.OrderProduct;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author zhangjiashun
 */
@Mapper
@Repository
public interface OrderDao {

    /**
     *
     * @param order
     * @return
     */
    int saveOrder(Order order);

    /**
     *
     * @param orderProductList
     * @return
     */
    int saveOrderProducts(List<OrderProduct> orderProductList);

    /**
     *
     * @param orderID
     * @return
     */
    List<OrderProduct> listOrderProductByOrderID(Long orderID);

    /**
     *
     * @param orderID
     * @param userID
     * @return
     */
    int countOrderByOrderAndUser(@Param("orderID") Long orderID, @Param("userID") Long userID);

    /**
     *
     * @param orderID
     * @return
     */
    int getOrderStatus(Long orderID);

    /**
     *
     * @param orderID
     * @return
     */
    Order getOrderByID(Long orderID);

    /**
     *
     * @param prepayID
     * @param orderID
     * @return
     */
    int recordPrepayID(@Param("prepayID") String prepayID, @Param("orderID") Long orderID);

    /**
     * 根据orderNo获取Order
     * @param orderNo
     * @return
     */
    Order getOrderByOrderNo(String orderNo);

    /**
     * 更新Order的状态
     * @param orderID
     * @param status
     * @return
     */
    int updateOrderStatus(@Param("orderID") Long orderID, @Param("status") int status);

    /**
     *
     * @param uid
     * @param index
     * @param count
     * @return
     */
    List<Order> getOrderByUser(@Param("uid") Long uid, @Param("index") Integer index,
                               @Param("count") Integer count);

    /**
     *
     * @param uid
     * @return
     */
    Integer getCountByUser(Long uid);

    /**
     * 分页查询所有订单
     * @param index
     * @param count
     * @return
     */
    List<Order> listOrder(@Param("index") Integer index,
                          @Param("count") Integer count);

    /**
     * 查询订单总数量
     * @return
     */
    Integer countOrder();
}
